package cn.lbd.arithmetic.dp;

public class Fibonacci {
    public static void main(String[] args) {
        /*for (int i = 1; i <= 10; i++) {
            System.out.println(fibonacci(i));
        }*/
        System.out.println(dpFibonacci(10));
    }

    public static int fibonacci(int n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        return fibonacci(n - 1) + fibonacci(n - 2);
    }

    public static int dpFibonacci(int n) {
        int dp[] = new int[n + 1];
        dp[1] = dp[2] = 1;
        for (int i = 3; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
            System.out.println(dp[i]);
        }
        System.out.println();
        return dp[n];
    }
}
